<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2019/10/29
 * Time: 15:16
 */

namespace app\admin\controller;


use think\Db;
use think\Request;

class Pcuser extends Base
{
    /**
     * 上传文件列表
     * @return mixed|\think\response\Json
     */
    public function index(){
        if(request()->isAjax ()){
            $params = input('param.');
            $where = [];
            if(isset($params['up_name']) && $params['up_name'] != ''){
                $where['user_username|user_phone'] = ['like', '%' . $params['up_name'] . '%'];
            }
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::table('up_u_user')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::table('up_u_user')
                ->where($where)
//                ->field('up_id, up_name, up_time')
                ->page($Nowpage,$limits)
                ->order('user_time desc')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }
    

    
    /**
     * 编辑
     * @return mixed|\think\response\Json
     */
    public function fileEdit(){
        $up_id = input('up_id');
        if(Request::instance()->isPost()){
            $params = input('param.');
            $update = [
                'user_username' => $params['up_name'],
            ];
            $res = Db::table('up_u_user')->where('user_id', $up_id)->update($update);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $up = Db::table('up_u_user')->where('user_id', $up_id)->find();
        $this->assign([
            'up_id' => $up_id,
            'up' => $up,
        ]);
        return $this->fetch('pcuser/fileedit');
    }
    
    /**
     * 删除文件
     * @return \think\response\Json
     */
    public function fileDel(){
        $up_id = input('id');
        $res = Db::table('up_u_user')->where('user_id', $up_id)->delete();
        if($res){
            return json(['code' => 200, 'msg' => '删除成功']);
        }else{
            return json(['code' => 100, 'msg' => '删除失败']);
        }
    }
    
    
}